/************************************************************
 * Copyright (C), 2022-2030, dina. Co., Ltd.
 * FileName:        def_serialport.h
 * Author:          Dan Yin
 * Date:            2022-11-23
 * Description:     the global define for serialport
 * Version:         1.0.0.0
 **********************************************************/

#ifndef DEF_SERIALPORT_H
#define DEF_SERIALPORT_H

#include <string.h>
#include <qmetatype.h>

#ifdef QT_NO_DEBUG
#if QT_PRO_DEBUG_ON_WINDOWS
#define DEF_COM_MACHINE                     "COM5"
#define DEF_COM_PRINTER                     "COM6"
#else
#ifdef QT_PROJECT_T1
#define DEF_COM_MACHINE                     "/dev/ttyS0"
#else
#define DEF_COM_MACHINE                     "/dev/ttyS9"
#endif
#define DEF_COM_PRINTER                     "/dev/ttyS3"
#endif
#else
#if QT_PRO_DEBUG_ON_WINDOWS
#define DEF_COM_MACHINE                     "COM5"
#define DEF_COM_PRINTER                     "COM6"
#else
#define DEF_COM_MACHINE                     "/dev/ttyUSB0"
#define DEF_COM_PRINTER                     "/dev/ttyUSB1"
#endif
#endif

#define DEF_MIN_PKG_SIZE                    18
#define DEF_PKG_HEADER1                     0x40
#define DEF_PKG_HEADER2                     0x4d
#define DEF_PKG_HEADER3                     0x44
#define DEF_PKG_HEADER4                     0x78
#define DEF_PKG_VERSION                     0x15
#define DEF_PKG_SOURCE_ID                   0x00

#define DEF_PKG_SYNC_SIZE                   4
#define DEF_PKG_VERSION_SIZE                1
#define DEF_PKG_MID_SIZE                    1
#define DEF_PKG_CMD_ID_SIZE                 1
#define DEF_PKG_DEST_ID_SIZE                1
#define DEF_PKG_FROM_ID_SIZE                1
#define DEF_PKG_FORMAT_SIZE                 1
#define DEF_PKG_SEQ_SIZE                    2
#define DEF_PKG_NOT_USED_SIZE               2
#define DEF_PKG_DATA_SIZE                   2
#define DEF_PKG_CRC_SIZE                    2

#define DEF_PKG_MIN_SIZE                    (DEF_PKG_SYNC_SIZE + DEF_PKG_VERSION_SIZE + (DEF_PKG_MID_SIZE + DEF_PKG_CMD_ID_SIZE) + DEF_PKG_DEST_ID_SIZE + DEF_PKG_FROM_ID_SIZE + DEF_PKG_FORMAT_SIZE + DEF_PKG_SEQ_SIZE + DEF_PKG_NOT_USED_SIZE + DEF_PKG_DATA_SIZE + 0 + DEF_PKG_CRC_SIZE)
#define DEF_PKG_FIRST_PART                  (DEF_PKG_SYNC_SIZE + DEF_PKG_VERSION_SIZE + (DEF_PKG_MID_SIZE + DEF_PKG_CMD_ID_SIZE) + DEF_PKG_DEST_ID_SIZE + DEF_PKG_FROM_ID_SIZE + DEF_PKG_FORMAT_SIZE + DEF_PKG_SEQ_SIZE + DEF_PKG_NOT_USED_SIZE + DEF_PKG_DATA_SIZE)

enum EUM_PKG_CMD_TYPE {
    E_PKG_CT_CMD,
    E_PKG_CT_DATA,
    E_PKG_CT_ACK,
    E_PKG_CT_REPLY,
    E_PKG_CT_NOTIFY
};

enum EUM_PKG_TARGET_TYPE {
    E_PKG_TT_MOTHER_BOARD,
    E_PKG_TT_MOTOR_DRIVER_BOARD,
    E_PKG_TT_PCR,
    E_PKG_TT_FLUORESCENCE,
    E_PKG_TT_HEATER,
    E_PKG_TT_ULTRASONIC,
    E_PKG_TT_BARCODE_SCANNER,
    E_PKG_TT_VIRTUAL_DEVICE,
    E_PKG_TT_UPPER_HOST
};

enum EUM_PKG_DATA_FORMAT {
    E_PKG_FMT_JSON,
    E_PKG_FMT_TEXT,
    E_PKG_FMT_BINARY
};

typedef struct ST_MIN_PKG_INFO {
    unsigned char ucHeader1;
    unsigned char ucHeader2;
    unsigned char ucHeader3;
    unsigned char ucHeader4;
    unsigned char ucVersion;
    unsigned char ucMachineID;
    unsigned char ucCommandID;
    unsigned char ucTargetID;
    unsigned char ucSourceID;
    unsigned char ucDataFormat;
    unsigned short usSequence;
    unsigned short usReserved;
    unsigned short usDataLength;
    unsigned short usPkgCRC;

    ST_MIN_PKG_INFO() {
        memset(this, 0, sizeof(ST_MIN_PKG_INFO));
    }
}MIN_PKG_INFO;

Q_DECLARE_METATYPE(ST_MIN_PKG_INFO);

#endif // DEF_SERIALPORT_H
